import java.io.*;
import java.util.ArrayList;

public class AddressIO
{
    private static String S = File.separator;

    public static ArrayList<String> readList(String filename)
    {
        ArrayList<String> result = new ArrayList<String>();
        try
        {
            BufferedReader reader = new BufferedReader(new FileReader(new File("email"+S+""+filename)));
            String read = "";
            do
            {
                read = reader.readLine();
                if(read != null)
                    result.add(read);
            }
            while (read != null);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            return new ArrayList<String>();
        }
        return result;
    }
    
    public static void writeList(String filename, ArrayList<String> toWrite)
    {
        File list = new File("email"+S+""+filename);     
        try
        {
            PrintStream printer = new PrintStream(new FileOutputStream(list));
            for(String s : toWrite)
            {
                printer.println(s);
            }
            printer.close();
        }
        catch (IOException a)
        {
            System.out.println("Saving the new file " + filename + " failed!");
        }
    }
}